Skip to content

Fix LCAO Hermitian matrix handling and EXX little-group density restoration - #7923

Merged
mohanchen merged 9 commits into
deepmodeling:developfrom
MagTheoryLab:codex/fix-lcao-eigensolver-hermitian
Sep 14, 2026
Merged

mohanchen merged 9 commits into
deepmodeling:developfrom
MagTheoryLab:codex/fix-lcao-eigensolver-hermitian

Conversation

@MagTheoryLab

@MagTheoryLab MagTheoryLab commented Sep 7, 2026

Copy link
Copy Markdown

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Related to #7914. This PR corrects authoritative-upper-triangle handling in the separate native ELPA and cuSolver implementations, and fixes an EXX little-group density-restoration issue exposed by enforcing that matrix contract. No separate issue is required.

The genelpa transform and fallback corrections from #7914 are now included through upstream develop, with TaoXia's original attribution preserved. They are no longer a pending dependency.

Unit Tests and/or Case Tests for my changes

Commands run

For the fresh six-way experiment, each diagnostic variant was rebuilt from commit 75ee7493a, then run in a separate case directory:

export OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1
export UCX_TLS=^xpmem

cmake --build "$BUILD_DIR" -j8 --target abacus_std_para
"$BUILD_DIR/abacus_std_para" --version

# VARIANT_BINARY identifies the corresponding rebuilt diagnostic executable.
timeout 180 mpirun -np 1 "$VARIANT_BINARY"

The experiment crosses two controlled factors:

  • little-group averaging: off / on;
  • solver path: old PZGEMM transform control / corrected PZHEMM / ScaLAPACK.

The old-transform control changes only the Cholesky-branch hemm('L','U',A,B) operation back to gemm('C','N',A,B) on the same current baseline. It does not revert the whole repository. All recorded ELPA decomposition states were 1; the fallback branch was not exercised in this experiment.

Both ELPA controls use the same diagnostic one-stage setting to avoid the previously observed installed two-stage library failure. This setting is not part of the production changes in the PR.

Result summary

All six calculations completed successfully on 2026-09-14.

Solver path Without little-group averaging: E (eV) With little-group averaging: E (eV)
Old PZGEMM transform control -189.4161946676993 -189.4406826021399
Corrected PZHEMM -189.4135167215100 -189.4406826018135
ScaLAPACK -189.4135167204379 -189.4406826023468

Without averaging, the maximum solver-dependent energy difference is 2.678 meV, while corrected PZHEMM and ScaLAPACK agree within 1.073e-9 eV.

After little-group averaging, all three paths agree within 5.33305e-10 eV, including the old PZGEMM control. They also give the same force absolute sum (0.000000 eV/Å) and stress absolute sum (2143.792554 kbar) at the output precision.

Matrix diagnostics were collected at the common solver entry point: 57 solves per case, 342 complete H/S and eigenpair records in total.

Solver path Without averaging: max ‖H−H†‖F With averaging: max ‖H−H†‖F With averaging: max full-H normalized residual
Old PZGEMM control 6.728525e-3 1.193271e-15 3.143836e-16
Corrected PZHEMM 6.692699e-3 1.223335e-15 2.603592e-16
ScaLAPACK 6.692699e-3 1.197093e-15 2.724060e-16

The raw matrix norms use ABACUS's internal matrix units. The normalized residual is

$$r = \frac{\| H C - S_{U} C E \|_{F}} {\| H \|_{F} \| C \|_{F} + \| S_{U} C E \|_{F}}.$$

Here, $E$ is the diagonal matrix of computed eigenvalues, $H$ is the original full Hamiltonian, and $S_{U}$ is reconstructed from the authoritative upper triangle of $S$.

Independent NumPy Cholesky/eigvalsh calculations give eigenvalue disagreements no larger than 4.885e-15 in internal energy units after averaging.

Without averaging, corrected PZHEMM and ScaLAPACK solve the upper-triangle-completed Hermitian problem with residuals below 3.020e-16, but their residuals against the original full H are approximately 3.511e-4. After averaging, both the upper-triangle contract and the full-matrix eigenproblem are satisfied at roundoff.

Matched conditions and provenance:

  • Source baseline: commit 75ee7493a.
  • Hardware: Intel Xeon CPU Max 9470C CPU.
  • All runs: one MPI rank, one OpenMP thread, one OpenBLAS thread.
  • GNU toolchain, OpenMPI 5.0.10, ELPA 2026.02.001-2603, LibXC 7.0.0, CMake 3.31.6; executable reports ABACUS v3.11.0-beta9.
  • Input: tests/08_EXX/08_KP_HSE_symm, preserving its SCF/EXX thresholds and three EXX outer updates.
  • SHA256 verification covered 2664 source/CMake files before building. Variant patches, source hashes, binary hashes, logs, and matrix records were retained.
  • All six cases exited 0 and produced #SCF IS CONVERGED#, final energy, and normal termination records.
  • The original source was subsequently restored, hash-verified, and rebuilt.

The retained focused regression coverage includes:

  • Poisoned-lower-triangle tests against an independent LAPACK reference: previous native ELPA 3/3 failed, corrected implementation 3/3 passed; previous real/complex cuSolver 2/2 failed, corrected implementation 2/2 passed.
  • Caller-owned native ELPA H/S buffers remain unchanged across two consecutive solves.
  • Two complex ELPA upper-triangle/fallback tests, three native ELPA block-size tests, and three K-point solver tests passed in the earlier merged-source validation.
  • Twelve EXX symmetry tests passed, including little-group/star-weight restoration, representative independence, separate spin channels, and spinor-density fixtures.

Checks not run, with reason

  • GPU tests were not rerun in this CPU six-way experiment; the earlier cuSolver positive/negative-control results are retained.
  • The complete solver CTest and four-rank complex ELPA runs previously encountered failures inside the installed two-stage ELPA library. They are not counted as passing verification.
  • Full-repository testing was not run; verification targets the changed solver contract and EXX restoration behavior.

What's changed?

This PR fixes two related correctness issues: Hermitian matrix input handling in native ELPA/cuSolver, and missing unitary little-group averaging before EXX k-star restoration.

1. Respect the authoritative upper triangles of H and S

For the generalized Hermitian eigenproblem,

$$HC=SC\varepsilon,\qquad S=U^\dagger U,\qquad \widetilde H=U^{-\dagger}HU^{-1}.$$

LCAO supplies authoritative upper triangles of H/S. A solver must not depend on stale or unspecified lower-triangle entries.

The changes:

  • Reconstruct private Hermitian H/S copies from the upper triangles before complex native ELPA solves.
  • Preserve caller-owned buffers and avoid reusing a decomposition of temporary overlap storage.
  • Select the upper triangle for real and complex cuSolver.
  • Retain upstream's genelpa Hermitian-transform and fallback corrections.
  • Correct the LAPACK regression workspace allocation to match its advertised size.

2. Average the IBZ density over its little group before star expansion

A k-star stores one representative operation for each distinct k point. It does not contain every operation fixing the irreducible k point modulo a reciprocal lattice vector.

Define the unitary little group as

$$G_{k}=\{g\mid gk=k+\mathbf G,\quad \mathbf G\text{ is a reciprocal lattice vector}\}.$$

The density must first be projected onto the invariant subspace:

$$\mathcal{P}_{k}[D] =\frac{1}{|G_{k}|}\sum_{g\in G_{k}}\mathcal{U}_{g}[D].$$

In ABACUS's transposed density storage convention,

$$\mathcal{U}_{g}[D]=M_{g}^{T} D M_{g}^{*},\qquad \mathcal{P}_{k}[D] =\frac{1}{|G_{k}|}\sum_{g\in G_{k}}M_{g}^{T} D M_{g}^{*},$$

where $M_{g}$ is the AO rotation matrix in the code's convention.

This group average preserves Hermiticity, is idempotent, and makes the density invariant under little-group operations. Operations reaching the same star member differ by a little-group operation, so averaging removes dependence on the selected representative.

The implementation collects the required unitary little-group operations and AO rotations, averages the IBZ density, and then performs the existing star expansion. The existing star-size weight is applied separately after averaging. Identity-only little groups bypass the additional averaging work.

A single valid rotation preserves Hermiticity. The missing average instead leaves the density inconsistent with the symmetry relations assumed by reduced EXX contractions, which can produce a non-Hermitian Hamiltonian.

The six-way experiment demonstrates the consequence directly: little-group averaging removes the solver-dependent energy split and restores the full Hamiltonian's Hermiticity and eigenproblem residuals to roundoff. Matching the historical reference energy alone would not establish correctness.

The HSE reference and explanatory README are updated using independently checked results. The original case inputs and tolerances are retained.

Governance Notes

  • INPUT/docs changes: no new parameter names or defaults. The existing EXX symmetry description is synchronized between its C++ registration, docs/parameters.yaml, and docs/advanced/input_files/input-main.md. The HSE reference and README document the corrected behavior.
  • Core module impact: native ELPA input preparation, cuSolver triangle selection, EXX AO-rotation preparation and density restoration, and their regression helpers. The average covers unitary little-group operations; existing antiunitary restoration handling is retained. No new full magnetic-group projection algorithm or gga_grad functionality is introduced.
  • Attribution: TaoXia's upstream genelpa corrections retain their original attribution. The native ELPA/cuSolver corrections, regression-helper changes, and EXX little-group restoration fix are included in this PR.
  • Exceptions requested: none. Local governance checks report no blockers. The additional PARAM reference in the EXX test fixture is balanced by a removed production reference, giving net zero global-reference growth.

@mohanchen mohanchen added Feature Discussed The features will be discussed first but will not be implemented soon Refactor Refactor ABACUS codes labels Sep 8, 2026
mohanchen and others added 3 commits September 8, 2026 09:22
Project multi-k density matrices before star restoration to preserve the symmetry assumed by reduced EXX contractions. Add complex-density and spin-channel regressions and update the Si HSE reference after independent solver and full-contraction checks.

@mohanchen mohanchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will handle this PR later.

@mohanchen mohanchen added the Symmetry This issue is related to symmetry label Sep 14, 2026
@MagTheoryLab MagTheoryLab changed the title Fix Hermitian upper-triangle handling in native ELPA and cuSolver Fix LCAO Hermitian matrix handling and EXX little-group density restoration Sep 14, 2026
@mohanchen
mohanchen merged commit ce02398 into deepmodeling:develop Sep 14, 2026
17 checks passed
Fisherd99 pushed a commit to Fisherd99/abacus-BSE that referenced this pull request Sep 22, 2026
…ration (deepmodeling#7923)

* fix(hsolver): honor Hermitian upper triangles in native ELPA and cuSolver

* fix(hsolver): honor Hermitian upper triangle in genelpa

(cherry picked from commit e27ef66)

* Fix second generalized ELPA transform

(cherry picked from commit 53208bf)

* fix(test): allocate the advertised LAPACK workspace

* fix(exx): average irreducible densities over the little group

Project multi-k density matrices before star restoration to preserve the symmetry assumed by reduced EXX contractions. Add complex-density and spin-channel regressions and update the Si HSE reference after independent solver and full-contraction checks.

* docs: synchronize EXX symmetry description with parameter source

---------

Co-authored-by: Chen Chengbing <1747193328@qq.com>
Co-authored-by: TaoXia <taoxia@mail.ustc.edu.cn>
Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
Co-authored-by: TRAE CLI <traecli@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Discussed The features will be discussed first but will not be implemented soon Refactor Refactor ABACUS codes Symmetry This issue is related to symmetry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants